package com.jinghua.treatment.service.impl;

import com.jinghua.treatment.entity.SysDoctor;
import com.jinghua.treatment.mapper.SysDoctorMapper;
import com.jinghua.treatment.service.SysDoctorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class SysDoctorServiceImpl  implements SysDoctorService{
    @Resource
    private SysDoctorMapper sysDoctorMapper;

    @Override
    public SysDoctor findByPhone(String phone) {
        SysDoctor result  = null;
        SysDoctor example  = new SysDoctor();
        example.setPhone(phone);
        List<SysDoctor> sysDoctorList =  sysDoctorMapper.selectByExample(example);
        if(sysDoctorList!=null && sysDoctorList.size()> 0 ){
            result = sysDoctorList.get(0);
        }
        return result;
    }

    @Override
    public SysDoctor regOrLogin(String phone) {
        SysDoctor doctor  = findByPhone( phone);
        if(doctor==null){
            doctor = new SysDoctor();
            doctor.setDoctorCreatedate(new Date());
            doctor.setLastlogindate(new Date());
            doctor.setPhone(phone);
            sysDoctorMapper.insert(doctor);
        }
        return doctor;
    }

}
